package edu.guigu.uiweixindemo.talk;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.Random;

import edu.guigu.uiweixindemo.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TalkFragment#newInstance} factory method to
 * create an instance of this fragment.
 *
 */
public class TalkFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private int mParam2;

    public TalkFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment HomeFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static TalkFragment newInstance(String param1, int param2) {
        TalkFragment fragment = new TalkFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putInt(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }


    private RecyclerView rv_talk;
    private TalkAdapter adapter;
    private ArrayList<TalkInfo> talkInfos = new ArrayList<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("TAG","onCreate~~~~~~~~~~~~~~~~~");
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getInt(ARG_PARAM2);
        }
        initData();
    }

    private void initData(){
        for (int i = 0; i < 20; i++) {
            talkInfos.add(new TalkInfo("微信小程序开发"));
            talkInfos.add(new TalkInfo("微信小程序开发2"));
            talkInfos.add(new TalkInfo("微信小程序开发3"));
            talkInfos.add(new TalkInfo("微信小程序开发4"));
            talkInfos.add(new TalkInfo("微信小程序开发5"));
            talkInfos.add(new TalkInfo("微信小程序开发6"));
            talkInfos.add(new TalkInfo("微信小程序开发7"));
        }
        adapter = new TalkAdapter();
        adapter.setTalkInfos(talkInfos);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        Log.d("TAG","onCreateView~~~~~~~~~~~~~~~~~");

        View view = inflater.inflate(R.layout.fragment_talk, container, false);

        rv_talk = view.findViewById(R.id.rev_talk);
        rv_talk.setLayoutManager(new LinearLayoutManager(getActivity()));
        rv_talk.setAdapter(adapter);
        return view;
    }
}